'''
陈超依 19377189
现代程序设计第四次作业
'''

from GraphStat.NetworkBuilder import node
import networkx as nx

def init_graph(parmaters):
    '''输入文件名，返回图'''
    LDictNode = node.init_node(parmaters)
    LNodes = open(parmaters, mode='r', encoding='utf-8').readlines()
    for i in range(len(LNodes)):
        if (LNodes[i] == '*Edges\n'):
            break
    LNodes = LNodes[(i+1):]
    G = nx.Graph()
    G.add_nodes_from(range(len(LDictNode)))
    for j in range(len(LNodes)):
        line = LNodes[j].split('\t')
        G.add_edge(int(line[0]), int(line[1]))
    return G

def print_graph(G : nx.Graph):
    f = open('E:/Py_Programs/week4/Graph.txt', mode = 'w', encoding='utf-8')
    for j in G.nodes:
        continue
    f.write('{}\n'.format(j))
    for i in G.edges():
        f.write('{}\n'.format(i))
        print(i)
    f.close()